<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<x:parse xml="${param.xmlstr}" var="xmlData" />
<c:set var="title">经费预算表</c:set>
<c:if test="${not empty param.title }"><c:set var="title">${param.title }</c:set></c:if>


<table  id="award_fjmucl" cellpadding="0" class="table01 t_css" width="100%" border="0" cellpadding="0" style="*border-bottom: #a1c0dc 1px solid;table-layout: fixed;" >
	<col width="5%" />
	<col width="5%" />
	<col width="30%" />
	<col width="60%" />
	
	<thead >
			<tr style="border:1px solid #B7D1E6">
				<th class="TblHead" align="center" >选择</th>
				<th class="TblHead" align="center" >序号</th>
				<th class="TblHead" align="center" >附件类型</th> 
		     	<th class="TblHead" align="center" >附件材料目录名称</th> 
				<!-- <th class="TblHead" align="center" >备注</th>  -->
			</tr>
	
	</thead>
	<tbody id="tab">
	<tr style="display:none" align="center">
		<td align="center">
			<input type="radio" class="radiobutton" name="award_fjmucl" >
		</td>
		<td align="center">
			<span name="award_fjmucl|list[0]@seq_no" >[index]</span> 
		</td>
		
		<td align="center">
			<cpt:select id="jcyjzdgxj_fjmu[index]"  name="jcyjzdgxj_fjmu" sqlParamVal="{grantCode:${param.grantCode}}" key="jcyjzdgxj_fjmu" style="width:80%;" onChange="initControlValue(this.id);changePrpAttach();" ></cpt:select>
			<input type="hidden" id="jcyjzdgxj_fjmu[index]_value" name="award_fjmucl|list[0]|jcyjzdgxj_fjmu_value" value="" label="附件类型"  class="required"/>
			<input type="hidden" name="award_fjmucl|list[0]|jcyjzdgxj_fjmu_name" value="" label="附件类型"  />
		</td>
		<td align="center">
			<input type="text" name="award_fjmucl|list[0]|fjclmu_name"   label="附件材料目录名称"  maxlength="200" style="width:80%" class=" input_text required" />
		</td>
		<!-- <td align="center">
			<input type="text" name="award_fjmucl|list[0]|fjclmu_beizhu"   label="备注"   style=" width:80%" class="required input_text"  maxlength="200"/>
		</td>  -->
	</tr>
	
	<c:set value="0" var="index" scope="page"/>
	<x:forEach select="$xmlData/data/award_fjmucl/list" var="list" >
	
	<c:choose>
		<c:when test="${index<10}" ><c:set value="0" var="flag" scope="page"/></c:when>
		<c:otherwise><c:set value="" var="flag" scope="page"/></c:otherwise>
	</c:choose>
	<tr align="center">
		<td align="center">
			<input type="radio" class="radiobutton" name="award_fjmucl" >
		</td>
		<td align="center">
			<span name="award_fjmucl/list[${flag}${index}]@seq_no" ><x:out select="$list/@seq_no"/></span> 
		</td>
			
		<td align="center">
			<%-- <c:set var="grantCode"><x:out select="$xmlData/data/proposal/grant_code" /></c:set> --%>
			<c:set var="jcyjzdgxj_fjmu"><x:out select="$list/jcyjzdgxj_fjmu_value" /></c:set>
			<cpt:select id="jcyjzdgxj_fjmu${index}" name="jcyjzdgxj_fjmu" sqlParamVal="{grantCode:${param.grantCode}}" value="${jcyjzdgxj_fjmu }" key="jcyjzdgxj_fjmu" style="width:80%;" onChange="initControlValue(this.id);changePrpAttach();" ></cpt:select>
			<input type="hidden" id="jcyjzdgxj_fjmu${index}_value" name="award_fjmucl/list[${flag}${index}]/jcyjzdgxj_fjmu_value" value="<x:out select="$list/jcyjzdgxj_fjmu_value" />" label="奖励等级"  class="required"/>
			<input type="hidden" name="award_fjmucl/list[${flag}${index}]/jcyjzdgxj_fjmu_name" label="附件类型" value="<x:out select="$list/jcyjzdgxj_fjmu_name" />" />
		</td>
		<td align="center">
			<input type="text" name="award_fjmucl/list[${flag}${index}]/fjclmu_name"  value="<x:out select="$list/fjclmu_name"/>"   label="附件材料目录名称" class=" required input_text " maxlength="200" style="width:80%"/>
		</td>
		<%-- <td align="center">
			<input type="text" name="award_fjmucl/list[${flag}${index}]/fjclmu_beizhu"  value="<x:out select="$list/fjclmu_beizhu"/>"   maxlength="200"
				label="备注"   style=" width:80%" class="required input_text" />
		</td>  --%>
	</tr>
	<c:set value="${index+1}" var="index" scope="page"/>
	</x:forEach>
</tbody>
</table>
<table width="98%" align="center" border="0">
	<tr style="border: 0"><td style="border: 0">
	<input class="button" name="cmdAddbefore" type=button value="添加" onclick="if(checkTabLimit('award_fjmucl',100,'附件材料目录最多只能添加100条')){addNewRow('award_fjmucl');try{top.resizeFrame();}catch(e){};}">
	<input class="button" name="cmdMovePrev" type=button value="上移" onclick="movePrev3('award_fjmucl','award_fjmucl')">
	<input class="button" name="cmdMoveNext" type=button value="下移" onclick="moveNext3('award_fjmucl','award_fjmucl')">
	<input class="button" name="cmddel" type=button  value="删除" onclick="deleteSelectedRow3qhh('award_fjmucl','附件材料目录');changePrpAttach();">
	</td></tr>
</table>	


<script type="text/javascript">

var v_same_prp_nums=0;

/**
 * 上移行
 * @param tblId
 * @returns {Boolean}
 */
function movePrev3qhh(tblId,selName) {
	if (!selName)
		selName = "";
	if ($("#" + tblId + " :radio[name*='" + selName + "']:checked").length == 0) {
		scmWarn(irisNotes.prevWarn);
		return false;
	}
	if ($("#" + tblId + " tr").length <= 4)
		return false;
	var trChecked = $("#" + tblId + " :radio[name*='" + selName + "']:checked")
			.parents("tr").first();// 取得被选中的行
	var trPrev = trChecked.prev();// 取得上一行
	var index = trChecked.get(0).rowIndex;// 获得行号
	if (index <= 4) {// 如果是第一行
		scmWarn(irisNotes.tabelMoveWarn1);
		return false;
	}
	//trChecked.remove();
	trPrev.before(trChecked);
	trChecked.find(":radio[name*='" + selName + "']").attr("checked", 'true');
	refreshRowINdex33(tblId);
}
 
 /**
	 * 上移行
	 * @param tblId
	 * @returns {Boolean}
	 */
	function movePrev3(tblId,selName) {
		if (!selName)
			selName = "";
		if ($("#" + tblId + " :radio[name*='" + selName + "']:checked").length == 0) {
			scmWarn(irisNotes.prevWarn);
			return false;
		}
		if ($("#" + tblId + " tr").length <= 2)
			return false;
		var trChecked = $("#" + tblId + " :radio[name*='" + selName + "']:checked")
				.parents("tr").first();// 取得被选中的行
		var trPrev = trChecked.prev();// 取得上一行
		var index = trChecked.get(0).rowIndex;// 获得行号
		if (index <= 2) {// 如果是第一行
			scmWarn(irisNotes.tabelMoveWarn1);
			return false;
		}
		//trChecked.remove();
		trPrev.before(trChecked);
		trChecked.find(":radio[name*='" + selName + "']").attr("checked", 'true');
		refreshRowINdex33(tblId);
	}

 /**
	 * 下移行
	 * @param tblId
	 * @returns {Boolean}
	 */
	function moveNext3(tblId,selName) {
		if (!selName)
			selName = "";
		if ($("#" + tblId + " :radio[name*='" + selName + "']:checked").length == 0) {
			scmWarn(irisNotes.nextWarn);
			return false;
		}
		if ($("#" + tblId + " tr").length <= 2) {
			return false;
		}
		var trChecked = $("#" + tblId + " :radio[name*='" + selName + "']:checked")
				.parents("tr").first();// 取得被选中的行
		var trNext = trChecked.next();
		var index = trChecked.get(0).rowIndex;// 获得行号
		if (index == $("#" + tblId + " tr").length - 1) {// 如果是第一行
			scmWarn(irisNotes.tabelMoveWarn2);
			return false;
		}
		//trChecked.remove();
		trNext.after(trChecked);
		trChecked.find(":radio[name*='" + selName + "']").attr("checked", "true");
		refreshRowINdex33(tblId);
	}
	 
	 /**
		 * 重新计算行号
		 * @param tblId
		 */
		function refreshRowINdex33(tblId){
			 //重新计算行号
			  $("#"+tblId+" tr").each(function(){
				   var seq=$(this).get(0).rowIndex;//获得行数
				   if(seq>1){//如果有行  显示时display行不计入类，故只减1
					   seq=seq-1;
					   var seq_no=$(this).find("[name$='seq_no']");
					   if(seq_no.is("span"))
						   seq_no.html(seq);
					   else
						   seq_no.val(seq);
					   
					   seq=""+(seq-1);
					   if(seq.length==1)
						   seq="0"+seq;
					  //替换相应的name参数的seq
					  $(this).find("input,span,textarea,select").each(function(){
						   var name=$(this).attr("name");
						   if(name!=null&&name!=""){
							   name=name.replace(/\[\d*\]/g,"["+seq+"]");
							   $(this).attr("name",name);
						   }
						   var id=$(this).attr("id");
						   if(id!=null&&id!=""){
							   id=id.replace(/\[\d*\]/g,"["+seq+"]");
							   $(this).attr("id",id);
							   id=id.replace(/\d+/g,""+seq+"");
							   $(this).attr("id",id);
						   }
						   var className=$(this).attr("class");
						   if(className!=null&&className!=""){
							   className=className.replace(/\[\d*\]/g,"["+seq+"]");
							   $(this).attr("class",className);
						   }
					   });
				   }
				 }
			  );

		}



/**
 * 删除一行
 * @param radioId 
 */
function deleteSelectedRow3qhh(tableId,message,nummin,warnMsg,selName){
	if(!selName)selName="";
	var tr=$("#"+tableId+" :radio[name*='"+selName+"']:checked").parents("tr");
	if(nummin==null)
		nummin=0;
	var length=tr.length;
	if(tr.length==0)
		tr=$("#"+tableId+" tr").filter(":last");
	else if(tr.length>1)
		tr=tr.first();

	if(tr.get(0).rowIndex-1==nummin){
		scmWarn(irisNotes.delWarn1);
		return false;
	}
	if(length==0){
		
			scmWarn(irisNotes.delWarn2);
		
		return false;
	}
	  if(!confirm(messageTip.deleteTip+message+"？"))
		  return false;
	  
	  //清空附件上传信息
	  var v_id=tr.find("td:eq(2)").find("input[name$='/jcyjzdgxj_fjmu_value']").val();
	  //得到附件相同的个数 v_same_prp_nums,如果只有一个,则清空附件信息中上传的附件内容
	  getSamePrpNums(v_id);
	  if(v_same_prp_nums==1){
		  $("#file_code"+v_id).val("");
		  $("#file_name"+v_id).text("");
		  $("#file_date"+v_id).text("");
		  $("#uploadsuccess"+v_id).hide();
	  }
	  
	  tr.remove();
	  refreshRowINdex33(tableId);
	  return true;
	  setSubmitOrg();
	  
	 
}
	
function getSamePrpNums(v_id){
	v_same_prp_nums=0;
	$("#award_fjmucl > tbody").find("tr:gt(0)").each(function(){
		var v=$(this).find("[name$='jcyjzdgxj_fjmu_value']").val();
		if(v==v_id){
			v_same_prp_nums=v_same_prp_nums+1;
		}
	});
}
	
	
//根据列表数据,显示需上传的附件
function changePrpAttach(){
	var prp_attach_arrays=new Array();
	
	var chushi_array = [1123,1124,1125,1126,1127,1135,1136,1137,1138,1139];
	var chushi_array_boolean=[false,false,false,false,false,false,false,false,false,false]
	$("#award_fjmucl > tbody").find("tr:gt(0)").each(function(){
		var v=$(this).find("[name$='jcyjzdgxj_fjmu_value']").val();
		if(v!=''){
			prp_attach_arrays.push(v);
			 for(var i=0;i<chushi_array.length;i++){
		       if(chushi_array[i]==v){
		    	   chushi_array_boolean[i]=true;
			     }
		     }
		}
	});
	
	for ( var i = 0; i < prp_attach_arrays.length; i++) {
		//id  showFlag:true显示  false隐藏
		//显示或隐藏附件列表内容
		setParent("seq_no_"+prp_attach_arrays[i],true);
	}
	
	for ( var i = 0; i < chushi_array.length; i++) {
		//id  showFlag:true显示  false隐藏
		//显示或隐藏附件列表内容
		if(!chushi_array_boolean[i]){
			setParent("seq_no_"+chushi_array[i],false);
		}
		
	}
	var row_num=1;

	
	//更新附件上传页面数据序号
	$("#prpContent_upload >tbody").find("tr").each(function(i){
		
		var v_st=$(this).attr('style');
		if(v_st!="display: none;" && v_st!="display: none"){
			$(this).find("span[id^='attach_seq']").text(row_num++);
		}
	});
	
}

function setParent(id,showFlag){
	var parentTr = $("#" + id).parent();
	  if(parentTr.is('tr')){
		  if(showFlag)
		  	parentTr.show();
		  else
		  	parentTr.hide();
	  }else{
		  if(showFlag)
		  	  parentTr.parent().show();
		  else
			  parentTr.parent().hide();
	  }
}


$(function(){
	changePrpAttach();
});

</script>
